package com.hellpro.lolbox.factory;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.hellpro.lolbox.moment.view.MomentContentFragment;

/**
 * 类描述:
 * 创建人:阿犇
 * 创建时间:2016/10/22
 * 备注:
 */

public class MomentFragmentFactory {

    private static final int FRAGMENT_MISS = 0;
    private static final int FRAGMENT_RUOFENG = 1;
    private static final int FRAGMENT_XIAODIAN = 2;
    private static final int FRAGMENT_CANG = 3;
    private static final int FRAGMENT_ZHI = 4;
    private static final int FRAGMENT_JY = 5;
    private static final int FRAGMENT_OTHRER = 6;


    //SparseArray:key是整形的key,根据整形的key来获取一个对象,效率比较高.
    public static SparseArray<Fragment> fragments = new SparseArray<>();

    //创建一个工厂方法,用来创建一个Fragment对象
    public static Fragment createFragment(int index) {
        //从集合中获取
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case FRAGMENT_MISS:
                case FRAGMENT_RUOFENG:
                case FRAGMENT_XIAODIAN:
                case FRAGMENT_CANG:
                case FRAGMENT_ZHI:
                case FRAGMENT_JY:
                case FRAGMENT_OTHRER:
                    fragment = new MomentContentFragment();
                    break;
            }
            //存到集合中
            fragments.put(index, fragment);
        }

        return fragment;
    }

}
